<% layout('./layout/layout') %>
<% block('header').append(`<style></style>`)%>
<div class="row">
  <div class="col-md-12">
    <div class="box box-info">
      <div class="box-header with-border">
        <h3 class="box-title"><%=dict.nameCn %></h3>
      </div>
      <!-- /.box-header -->
      <!-- form start -->
      <form action="<%=assetsPath %>/dict/saveField" method="post" class="form-horizontal" novalidate>
        <div class="box-body">
          <% if(dict.remark) { %>
            <blockquote ><%- dict.remark %></blockquote>
            <% } %>
          <% if(dict.valueType === 'string'){ %>
          <div class="form-group">
            <label for="title" class="col-sm-2 control-label"><%=dict.nameCn %></label>
            <div class="col-sm-10">
              <% if(dict.value && dict.value.length >60) { %>
              <textarea name="value" rows="5" class="form-control"><%=dict.value %></textarea>
              <% } else { %>
              <input name="value" class="form-control" value="<%=dict.value || '' %>"  placeholder="属性值"  >
              <% } %>
            </div>
          </div>
          <% } %>
          <% if(dict.valueType === 'object'){ %>
            <% for (let key in dict.value) {  %>
            <div class="form-group">
              <label for="path" class="col-sm-2 control-label"><%=dict.value[key].name %></label>
              <div class="col-sm-10">
                <input name="value[<%=key %>][name]" type="hidden" value="<%=dict.value[key].name || ''%>" >
                <input name="value[<%=key %>][value]" class="form-control" value="<%=dict.value[key].value || ''%>"  placeholder="属性值">
              </div>
            </div>
            <% } %>
          <% } %>
          <% if(dict.valueType === 'array'){ %>
            <%  dict.value.forEach((item, index)=> { %>
            <div class="form-group">
              <label for="path" class="col-sm-2 control-label"><%=item.name%></label>
              <div class="col-sm-10">
                <input name="value[<%=index%>][name]" type="hidden" value="<%=item.name %>" >
                <input name="value[<%=index%>][value]" class="form-control" value="<%=item.value || ''%>"  placeholder="属性值">
              </div>
            </div>
            <% }) %>
          <% } %>
          <% if(dict.valueType === 'arrayfive'){ %>
            <% dict.value.forEach((item, index)=> { %>
              <div class="form-group">
                <label for="path" class="col-sm-2 control-label"><%=item.name%></label>
                <div class="col-sm-2">
                  <input name="value[<%=index%>][name]" type="hidden" value="<%=item.name %>" >
                  <input name="value[<%=index%>][key]" type="hidden" value="<%=item.key %>" >
                  <input name="value[<%=index%>][value]" class="form-control" value="<%=item.value || ''%>"  placeholder="属性值">
                </div>
                <% if('value1' in item) { %>
                <div class="col-sm-2"><input name="value[<%=index%>][value1]" class="form-control" value="<%=item.value1 || ''%>"  placeholder="属性值[value1]"></div>
                <% } %>
                <% if('value2' in item) { %>
                <div class="col-sm-2"><input name="value[<%=index%>][value2]" class="form-control" value="<%=item.value2 || ''%>"  placeholder="属性值[value2]"></div>
                <% } %>
                <% if('value3' in item) { %>
                <div class="col-sm-2"><input name="value[<%=index%>][value3]" class="form-control" value="<%=item.value3 || ''%>"  placeholder="属性值[value3]"></div>
                <% } %>
                <% if('value4' in item) { %>
                <div class="col-sm-2"><input name="value[<%=index%>][value4]" class="form-control" value="<%=item.value4 || ''%>"  placeholder="属性值[value4]"></div>
                <% } %>
              </div>
            <% }) %>
          <% } %>
          <% if(dict.valueType === 'arraymuti'){ %>
            <% dict.value.forEach((item, index)=> { %>
              <% if(Object.prototype.toString.call(item) === '[object Array]') { %>
                <% item.forEach(function(sub, sindex) { %>
                  <div class="form-group">
                    <label for="path" class="col-sm-2 control-label"><%=sub.name%></label>
                    <div class="col-sm-10">
                      <input name="value[<%=index%>][<%=sindex %>][name]" type="hidden" value="<%=sub.name %>" >
                      <input name="value[<%=index%>][<%=sindex %>][key]" type="hidden" value="<%=sub.key %>" >
                      <input name="value[<%=index%>][<%=sindex %>][value]" class="form-control" value="<%=sub.value || ''%>"  placeholder="属性值">
                    </div>
                  </div>
                <% }) %>
               <% } else { %>
                <div class="form-group">
                  <label for="path" class="col-sm-2 control-label"><%=item.name%></label>
                  <div class="col-sm-10">
                    <input name="value[<%=index%>][name]" type="hidden" value="<%=item.name %>" >
                    <input name="value[<%=index%>][key]" type="hidden" value="<%=sub.key %>" >
                    <input name="value[<%=index%>][value]" class="form-control" value="<%=item.value || ''%>"  placeholder="属性值">
                  </div>
                </div>
               <% } %> 
            <% }) %>
          <% } %>
        <!-- /.box-body -->
        <div class="box-footer">
          <div class="col-sm-offset-2 col-sm-10">
            <input name="valueType" type="hidden" value="<%=dict.valueType %>" >
            <input name="_id" type="hidden" value="<%=dict._id%>" >
            <button type="submit" class="btn btn-info ">保存</button>
            <button type="reset" class="btn btn-default">重置</button>
          </div>
        </div>
        </div>
        <!-- /.box-footer -->
      </form>
    </div>
  </div>
</div>
<% block('footer').append(`<script>
    jQuery(function() {

    })
</script>`)%>